Fuxor
Very simple DI for node.
const fuxor = require('fuxor')
fuxor.add('fs', {
readFileSync: function () {
return 'Not really a file'
}
})
const fs = require('fs')
console.log(fs.readFileSync('not really', 'anything', { whatever:'you want'}))
API
Add
Add what should be returned when the module is required
const fuxor = require('fuxor')
fuxor.add('fs', {
readFileSync: function () {
return 'Not really a file'
}
})
fuxor.add({ name: 'fs', result: {
readFileSync: function () {
return 'Not really a file'
}
}});
fuxor.add([{ name: 'fs', result: {
readFileSync: function () {
return 'Not really a file'
}
}, {
name: 'request',
result: function () {
return 'Not really a file'
}
}])
Clear
Clear all entries
const fuxor = require('fuxor');
fuxor.clear()
remove
Remove individual module to restore the original module
const fuxor = require('fuxor')
fuxor.remove('your-module')
reset
Resets back to default require behavior
const fuxor = require('fuxor')
fuxor.reset()
org
Load a directory structure as an org
const fuxor = require('fuxor')
fuxor.init({
name: '@fuxor',
path: path.join(__dirname, './modules'),
})
const myModule = require('@fuxor/myModule')
const myOtherModule = require('@fuxor/myOtherModule')